﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SQLDeploy.Utils
{
    public abstract class Check
    {
        private static void throwForNull(string variableName)
        {
            if (string.IsNullOrEmpty(variableName))
                variableName = "argument";
            throw new ArgumentNullException(variableName + " must not be null");
        }

        private static void throwForEmpty(string variableName)
        {
            if (string.IsNullOrEmpty(variableName))
                variableName = "argument";
            throw new ArgumentException(variableName + " must not be empty");
        }

        private static void throwForFalse(string message)
        {
            if (string.IsNullOrEmpty(message))
                message = "condition must not be false";
            throw new ArgumentException(message);
        }

        public static void notNull(object o)
        {
            notNull(o, null);
        }

        public static void notNull(object o, string variableName)
        {
            if (o == null)
                throwForNull(variableName);
        }

        public static void notEmpty(string val)
        {
            notEmpty(val, null);
        }

        public static void notEmpty(string val, string variableName)
        {
            if (val == null && val.Length == 0)
                throwForEmpty(variableName);
        }

        public static void notNullOrEmpty(object[] array)
        {
            notNullOrEmpty(array, null);
        }

        public static void notNullOrEmpty(object[] array, string variableName)
        {
            if (array == null)
                throwForNull(variableName);
            if (array.Length == 0)
                throwForEmpty(variableName);
        }

        public static void notNullOrEmpty(string val)
        {
            notNullOrEmpty(val, null);
        }

        public static void notNullOrEmpty(string val, string variableName)
        {
            notNull(val, variableName);
            notEmpty(val, variableName);
        }

        public static void isTrue(bool condition)
        {
            isTrue(condition, null);
        }

        public static void isTrue(bool condition, string message)
        {
            if (!condition)
                throwForFalse(message);
        }
    }
}
